<%--
  Created by IntelliJ IDEA.
  User: CMCC
  Date: 2016/8/30
  Time: 16:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    <link rel="stylesheet" href="css/contractInfo.css" />
    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="js/handlebars-v3.0.3.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript">
        var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
        window.onload=function(){
            var oUserInfo=document.getElementById('userInfo');
            var ocCntractInfo=document.getElementById('contractInfo');
//            var oLogInfo=document.getElementById('logInfo');
            oUserInfo.onmousedown=function(){
                ocCntractInfo.style.backgroundColor="#fff";
                ocCntractInfo.style.color="#000";
                oUserInfo.style.backgroundColor="#324e75";
                oUserInfo.style.color="#fff";
            };
            ocCntractInfo.onmousedown=function(){
                oUserInfo.style.backgroundColor="#fff";
                oUserInfo.style.color="#000";
                ocCntractInfo.style.backgroundColor="#324e75";
                ocCntractInfo.style.color="#fff";
            }
            ocCntractInfo.onclick=function(){
                window.location.href= hosturl+'/contractInfo.jsp';
            };
//            oLogInfo.onclick=function(){
//                window.location.href='logMana.jsp';
//            };
            //添加合同信息


        }
    </script>
    <title>用户信息</title>
</head>

<body>
<div class="top">
    <div class="top-left">
        <p class="top-left">合同管理系统</p>
    </div>
    <div class="top-right">
        <p class="p1">欢迎管理员<span class=""> <%=session.getAttribute("SName")%> </span>的到来 <a href="javascript:logout();"id="logout">注销 </a></p>
    </div>
</div>
<div class="left-block">
    <ul>
        <li id="contractInfo" class="uleft-index">合同管理</li>
        <li id="userInfo" class="cleft-index">用户信息</li>
        <%--<li id="logInfo" class="uleft-index">日志管理</li>--%>
    </ul>
</div>
<div class="main-part">
    <ul>
        <li class="right-label">用户信息</li>
        <!--<li class=""><input class="right-btn" type="button" value="修改合同信息" /></li>-->
        <!--<li class=""><input class="right-btn" type="button" value="搜索" /></li>-->
        <li>
            <table id="table1" class="table table-bordered table-striped table-hover">
                <thead>
                <tr>
<!--                    <th>编号</th>-->
                    <th>用户名</th>
                    <th>密码</th>
                    <th>部门</th>
                    <th>OA邮箱</th>
                    <th>139邮箱</th>
                    <th>姓名</th>
                    <th>电话</th>
                    <th>PS</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="tableList">
                </tbody>
                <%--<script id="table-template" type="text/x-handlebars-template">--%>
                    <%--{{#each contract}}--%>
                    <tr>
<!--                        <td id="id">{{id}}</td>-->
                        <td id="userName">{{userName}}</td>
                        <td id="password"></td>
                        <td id="department">{{department}}</td>
                        <td id="oa">{{OA}}</td>
                        <td id="emailAddress" >{{emailaddress}}</td>
                        <td id="name">{{name}}</td>
                        <td id="phone">{{phone}}</td>
                        <td id="primarySalt">{{primarySalt}}</td>
                        <td>
                            <a href="javascript:update();">更改密码</a>
                        </td>
                    </tr>
                    <%--{{/each}}--%>
                <%--</script>--%>
                <script type="text/javascript">
                    $(document).ready(function() {
//                        var id = document.getElementById('id');
                        var userName = document.getElementById('userName');
                        var password = document.getElementById('password');
                        var department = document.getElementById('department');
                        var oa = document.getElementById('oa');
                        var emailAddress = document.getElementById('emailAddress');
                        var name = document.getElementById('name');
                        var phone = document.getElementById('phone');
                        var primarySalt = document.getElementById('primarySalt');
                        mui.ajax("/user/byId", {
                            data: { },
                            dataType: "json",
                            type: "post",
                            timeout: 10000,
                            success: function(datas) {
                                if(datas.status=="refuse"){
                                    alert(datas.description);
                                    window.location.href = 'login.html';
                                }else{
//                                    id.innerText=datas.body.id;
                                    userName.innerText=datas.body.userName;
                                    password.innerText="**************";
                                    department.innerText=datas.body.department;
                                    oa.innerText=datas.body.oa;
                                    emailAddress.innerText=datas.body.emailAddress;
                                    name.innerText=datas.body.name;
                                    phone.innerText=datas.body.phone;
                                    primarySalt.innerText=datas.body.primarySalt;
                                }
                            },
                            error: function(xhr, type, errorThrown) {
                                console.log(type);
                            }
                        });
                        window.onload=function(){
                            var oLogout=document.getElementById('logout');
                            oLogout.onclick=function(){
                                window.location.href= hosturl+'/login.jsp';
                            };
                        }
                    });
                </script>

                </tbody>
            </table>
        </li>
    </ul>
</div>
<input id="handle_status" value="" hidden="hidden">
</body>
</html>
<script type="text/javascript">
    function update(){
        layer.open({
            type: 2,
            title: '修改密码',
            shadeClose: true,
            shade: [0.3, '#000'],
            area: ['500px', '500px'],
            content: 'updateUserPass.html',
            end: function () {
                var handle_status = $("#handle_status").val();
                if ( handle_status == 'OK' ) {
                    layer.msg('修改密码成功！请重新登录！',{
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    setTimeout(logout(),4000);
                } else if ( handle_status == 'none' ) {
                    layer.msg('修改密码失败！',{
                        icon: 2,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    window.location.reload();
                }
            }
        });
        layer.iframeAuto();
    };
    function logout(){
        mui.ajax(hosturl+"/user/logout", {
            data: { },
            dataType: "json",
            type: "get",
            timeout: 10000,
            success: function(datas) {
                if(datas.status=="ok"){
                    window.location.href = hosturl+'/login.jsp';
                }else{
                    alert(datas.description);
                }
            },
            error: function(xhr, type, errorThrown) {
                console.log(type);
            }
        });
    };

</script>
